home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / java / slideshow / sources (complete) / aboutdialog.java next >
Encoding:
Java Source  |  2000-06-23  |  2.5 KB  |  97 lines

  1. import java.awt.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4.  
  5. public class AboutDialog extends Dialog
  6. {
  7.     //DECLARE_CONTROLS
  8.     //Insert "AboutDialog Declare Controls"
  9.     Label label1;
  10.     Button okButton;
  11.  
  12.     public AboutDialog(Frame parent, boolean modal)
  13.     {
  14.         super(parent, modal);
  15.  
  16.         //INIT_CONTROLS
  17.         
  18.         //Setting up the dialog the way we want it.
  19.         //Insert "AboutDialog Dialog Setup"
  20.         GridBagLayout gridBagLayout;
  21.         gridBagLayout = new GridBagLayout();
  22.         setLayout(gridBagLayout);
  23.         setVisible(false);
  24.         setSize(277,100);
  25.         setBackground(new Color(15724527));
  26.         setTitle("About...");
  27.         setResizable(false);
  28.  
  29.         //Setting up label1 and placing it in the layout
  30.         //Insert "AboutDialog label1 Setup"
  31.         label1 = new Label("This is my cool SlideShow Application!",Label.CENTER);
  32.         GridBagConstraints gbc;
  33.         gbc = new GridBagConstraints();
  34.         gbc.gridx = 1;
  35.         gbc.gridy = 1;
  36.         gbc.fill = GridBagConstraints.NONE;
  37.         gbc.insets = new Insets(0,0,0,0);
  38.         ((GridBagLayout)getLayout()).setConstraints(label1, gbc);
  39.         add(label1);
  40.  
  41.         //Setting up okButton and placing it in the layout
  42.         //Insert "AboutDialog okButton Setup"
  43.         okButton = new Button();
  44.         okButton.setLabel("OK");
  45.         gbc = new GridBagConstraints();
  46.         gbc.gridx = 1;
  47.         gbc.gridy = 2;
  48.         gbc.fill = GridBagConstraints.NONE;
  49.         gbc.insets = new Insets(0,0,0,0);
  50.         ((GridBagLayout)getLayout()).setConstraints(okButton, gbc);
  51.         add(okButton);
  52.  
  53.         //REGISTER_LISTENERS
  54.         //Registering our ActionListner with the okButton
  55.         //Insert "AboutDialog Register Listeners"
  56.         Action lAction = new Action();
  57.         okButton.addActionListener(lAction);
  58.     }
  59.  
  60.     /**
  61.      * Shows or hides the component depending on the boolean flag b.
  62.      * @param b  if true, show the component; otherwise, hide the component.
  63.      * @see java.awt.Component#isVisible
  64.      */
  65.     public void setVisible(boolean b)
  66.     {
  67.         //Place the dialog in the Macintosh Alert Position
  68.         //Insert "AboutDialog setVisible"
  69.         if(b)
  70.         {
  71.             Dimension bounds = Toolkit.getDefaultToolkit().getScreenSize();
  72.             Dimension abounds = getSize();
  73.     
  74.             setLocation((bounds.width - abounds.width) / 2,
  75.                  (bounds.height - abounds.height) / 3);
  76.         }
  77.         super.setVisible(b);
  78.     }
  79.  
  80.     //Innerclass for handling ActionEvents
  81.     //Insert "AboutDialog ActionListener"
  82.     class Action implements ActionListener
  83.     {
  84.         public void actionPerformed(ActionEvent event)
  85.         {
  86.             okButton_Clicked(event);
  87.         }
  88.     }
  89.     
  90.     //Respond to button clicked ActionEvents from the okButton
  91.     //Insert "AboutDialog okButton_Clicked"
  92.     void okButton_Clicked(ActionEvent event)
  93.     {
  94.         setVisible(false);
  95.     }
  96. }
  97.